package DAO;


import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import Model.borrow;

/**
 * 借书表的操作
 * @author MacBook
 *
 */
public class borrowDAO {
	//加入借书记录
	public static void save(Session session,borrow b){
		session.save(b);
	}
	//查找用户借书记录
	@SuppressWarnings("deprecation")
	public static borrow findRecord(Session session,int userid,int bookid){
		String hql = "from borrow where user_id = ? and book_id = ?";
		Query<?> query = session.createQuery(hql);
		query.setParameter(0, userid);
		query.setParameter(1, bookid);
		borrow b = null;
		List list = query.list();
		if(list.size()>0)
			b = (borrow)list.get(0);
		return b;
	}
	//删除借书记录--还书服务
	public static void removeRecord(Session session,int userid,int bookid){
		String hql = "delete from borrow where user_id = ? and book_id = ?";
		Query<?> query = session.createQuery(hql);
		query.setParameter(0, userid);
		query.setParameter(1, bookid);
		query.executeUpdate();
	}
}
